﻿Public Class SubThanhToanTheForm
    Dim SoTien As Double
    Dim MaTheTinDung As String
    Dim Thang As String
    Dim Nam As String    
    Sub New(ByVal SoTien As Double, ByVal MaTheTinDung As String, ByVal Thang As String, ByVal Nam As String)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.SoTien = SoTien
        Me.MaTheTinDung = MaTheTinDung
        Me.Thang = Thang
        Me.Nam = Nam
        txtSoTien.Text = SoTien
    End Sub

    Private Sub btTra_Click(sender As System.Object, e As System.EventArgs) Handles btTra.Click
        If txtSoTien.Text.Trim().Length = 0 Or Not IsNumeric(txtSoTien.Text) Then
            MessageBox.Show("Xin vui lòng nhập vào số tiền")
            Return
        End If
        If txtExtra.Text.Trim().Length > 0 And Not IsNumeric(txtExtra.Text) Then
            MessageBox.Show("Xin vui lòng nhập vào số tiền phải trả thêm")
            Return
        End If
        Dim dt As DataTable = DB_Provider.Read_schema("ChiTietTraTinDung")
        Dim dr As DataRow = dt.NewRow()
        dr("MaTheTinDung") = MaTheTinDung
        Dim tmp As Double = Double.Parse(txtSoTien.Text)
        If (txtExtra.Text.Trim().Length > 0) Then
            tmp = tmp + Double.Parse(txtExtra.Text)
        End If
        dr("SoTien") = tmp
        dr("NgayTra") = Date.Now.ToShortDateString()
        dr("Thang") = Thang
        dr("Nam") = Nam
        dt.Rows.Add(dr)
        DB_Provider.Write(dt, "ChiTietTraTinDung")
        Dim MaNganHang As Integer = TheTinDungDAO.MaNganHang(MaTheTinDung)
        ThanhToanTheDAO.TraNo(tmp, MaNganHang)
        Me.DialogResult = DialogResult.OK        
    End Sub
End Class